package org.foxas.ui
{
	import flash.events.MouseEvent;
	import flash.text.TextFormatAlign;
	
	import org.foxas.display.FSprite;

	public class FConfirm extends FSprite
	{
		private var yesListener:Function;
		private var noListener:Function;
		public static var YES:String = "YES";
		public static var NO:String = "NO";
		public function FConfirm(_title:String,_yesListener:Function=null,_noListener:Function=null,_btnYesText:String="",_btnNoText:String="")
		{
			super();
			if(_btnYesText==""){
				_btnYesText = YES;
			}
			if(_btnNoText==""){
				_btnNoText = NO;
			}
			yesListener=_yesListener;
			noListener=_noListener;
			var title:FLabel = new FLabel(_title);
			title.width = 200;
			title.textAlign = TextFormatAlign.CENTER;
			this.addChild(title);
			var btnYes:FButton = new FButton(_btnYesText,0,title.height+10,onYES);
			this.addChild(btnYes);
			var btnNo:FButton = new FButton(_btnNoText,btnYes.width+10,title.height+10,onNO);
			this.addChild(btnNo);
			FUI.addChild(this);
		}
		private function onYES(_e:MouseEvent):void{
			destruct();
			if(yesListener!=null){
				yesListener(_e);
			}
		}
		private function onNO(_e:MouseEvent):void{
			destruct();
			if(noListener!=null){
				noListener(_e);
			}
		}
		override public function destruct():void{
			FUI.removeChild(this);
			while(this.numChildren){
				if(this.getChildAt(0) is FSprite){
					(this.getChildAt(0) as FSprite).destruct();
				}
			}
			super.destruct();
		}
	}
}